package com.hiwan.unions.adapter.fragmentAdapters;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hiwan.unions.R;
import com.hiwan.unions.adapter.bean.NewsBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by llg on 2017/7/9.
 */
public class NewsAdapter extends BaseAdapter {
    private List<NewsBean> cDates = new ArrayList<NewsBean>();
    private Context mContext;
    protected SharedPreferences userInfo;

    public NewsAdapter(Context contex, List<NewsBean> cDates) {
        this.mContext = contex;
        this.cDates = cDates;
    }

    @Override
    public int getCount() {
        return cDates.size();
    }

    @Override
    public Object getItem(int position) {
        return cDates.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_news_a, null);
            holder.ItemDate = (TextView) convertView.findViewById(R.id.Text_date);
            holder.ItemContent = (TextView) convertView.findViewById(R.id.Text_content);
            holder.Text_Title = (TextView) convertView.findViewById(R.id.Text_Title);
            holder.view = convertView.findViewById(R.id.text_bt);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        setData(holder, position);
        return convertView;
    }

    /**
     * 设置viewHolder的数据  1型
     *
     * @param holder
     * @param itemIndex
     */
    private void setData(ViewHolder holder, int itemIndex) {
        if (itemIndex == 0) {
            holder.view.setVisibility(View.VISIBLE);
        } else {
            holder.view.setVisibility(View.GONE);
        }
        holder.ItemDate.setText(cDates.get(itemIndex).getCreate_time());
        holder.ItemContent.setText(cDates.get(itemIndex).getContent());
        holder.Text_Title.setText(cDates.get(itemIndex).getTitle());
    }

    private class ViewHolder {
        private View view;
        private TextView ItemDate;
        private TextView ItemContent;
        private TextView Text_Title;

    }
}